package com.bw.p19.utils

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader

object LoadImage {
    /**
     * 封装绑定适配器  bindingAdapter 实现在xml中的imageView空间可直接给网络图片的路径
     *
     */
    @JvmStatic
    @BindingAdapter("img_url")
    fun loadPic(imageView: ImageView,url:String?){
        if (url!=null){
            Glide.with(imageView.context).load(url).into(imageView)
        }
    }
    /**
     * 显示轮播图
     */
    @JvmStatic
    @BindingAdapter("banner_url")
    fun loadBanner(banner:Banner,list: MutableList<String>?){
        if (list!=null){
            if (list.isNotEmpty()){
                banner.setImages(list)
                    .setImageLoader(object :ImageLoader(){
                        override fun displayImage(
                            context: Context?,
                            path: Any?,
                            imageView: ImageView?
                        ) {
                            Glide.with(context!!).load(path).into(imageView!!)
                        }

                    }).start()
            }
        }
    }
}